#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 8, INF = 0x3f3f3f3f;

int n, m;
char a[N][N];
int c[N][N];
pair<int, int> mx;

bool check(int i, int j)
{
    return a[i][j] == '#' && a[i + 1][j] == '#' && a[i][j + 1] == '#' && a[i + 1][j + 1] == '#';
}

void Max(pair<int, int>& t, int x, int y)
{
    int cnt = c[t.first][t.second];
    for (int i = x;i <= x + 1;i++)
        for (int j = y;j <= y + 1;j++)
            if (c[i][j] > cnt) {
                cnt = c[i][j];
                t = { i,j };
            }
}

void add(int i, int j) {
    c[i][j]++;
    c[i + 1][j]++;
    c[i][j + 1]++;
    c[i + 1][j + 1]++;
}

bool check()
{
    int flag = 0;
    memset(c, 0, sizeof c);
    mx = { 1,1 };
    for (int i = 1;i < n;i++)
        for (int j = 1;j < m;j++)
            if (check(i, j)) {
                flag = 1;
                add(i, j);
                Max(mx, i, j);
            }
    return flag;
}

void solve()
{
    cin >> n >> m;
    for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) cin >> a[i][j];

    int ans = 0;
    while (check()) {
        ans++;
        a[mx.first][mx.second] = '.';
    }

    cout << ans << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"(2
5 5
####.
##.##
#####
.####
##.#.
2 2
..
..
)");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}